<?php
	session_start();
	require("connect.php");
	$link = connect_APO();
	
	require("check.php");
	is_admin();
	
	require("header+logoutB.php");
	headerL();
	
	$sql = sprintf("SELECT * From midweeks ORDER BY StartTime ASC");
	$result = mysql_query($sql);
	$numberMidweeks=0;
	while($row = mysql_fetch_array($result)){
		$numberMidweeks += 1;
		$midweekLongName[] = $row["Name"];
		$hold = $row["Name"];
		$midweekLongNameUnd[] = str_replace(" ", "_", $hold);
		$midweekShortName[] = $row["SName"];
		$midweekSTime[] = $row["StartTime"];
		$midweekETime[] = $row["EndTime"];
		$midweekDay[] = $row["Day"];
		$midweekLeaders[] = $row["Leader1"];
		$midweekLeaders[] = $row["Leader2"];
	}
	
	
	echo "<html>
<body class='main'>

<FONT class='mainFont'>
	<CENTER>
    <!--<p><img src = 'images/apopic.jpg'></p>-->
    <br>
	<br>
	<div class='headerTable'>
		<div id='links'>
			<div id='backLink'> <A href='newMid.php'>Add a Midweek</A></div>
		</div>
		<b class='b1f'></b><b class='b2f'></b><b class='b3f'></b><b class='b4f'></b>
			<div class='contentf'>
				<div class = 'headerText'>
					Midweeks:
				</div>
				<div id='headingMidweeks'>
						<b id='midweekName'>Name</b>
						<b id='day'>Day</b>
						<b id='time'>Start-End Time</b>
						<b id='leaders'>Leader(s)</b>
						<b id='edit'>&nbsp;</b>
						<b id='removeMid'>&nbsp;</b>
					</div>
				<div id = 'allMidweeks'>
					";
					for ($mid = 0; $mid<$numberMidweeks; $mid +=1){
						echo "<div id='midweek'> 
							<div id='midweekName'>".$midweekShortName[$mid]."</div>
							<div id='day'>".$midweekDay[$mid]."
							</div>
							<div id='time'>".$midweekSTime[$mid]." - ".$midweekETime[$mid]."
							</div>
							<div id='leaders'>";
							if($midweekLeaders[2*$mid] != null){
								echo $midweekLeaders[2*$mid];
								$leader1 = true;
							}
							if($midweekLeaders[2*$mid+1] != null){
								if($leader1)
									echo ", ".$midweekLeaders[2*$mid+1];
							}
							echo "&nbsp;</div>
							<div id='edit'>
							<a href='newMid.php?midweek=$midweekLongNameUnd[$mid]'>Edit</a>
							</div>
							<div id='removeMid'>
							<a href='removeMidweek.php?midweek=$midweekLongNameUnd[$mid]'>Remove</a>
							</div>
							</div>";
					}
			echo "</div>
			</div>
		<b class='b4f'></b><b class='b3f'></b><b class='b2f'></b><b class='b1f'></b>
	</div>
	</CENTER>
</FONT>
</body>
</html>";

	require("footer.php");
	footer();
	mysql_close($link);
?>